import requests from "@/api/axios";

// 获取网站相关信息
export const websiteInfo = function () {
    return requests('websiteinfo')
}

// 登录
export const Login = function (userData) {
    return requests({
        url: 'login/',
        method: 'post',
        data: {
            userData
        }
    })
}

// 注册
export const Register = function (userData) {
    return requests.post('register/', {userData}
    )
}

// 注销
export const Logout = function () {
    return requests('logout/')
}

// 获取验证码
export const GetVerificationCode = function () {
    return requests({
        url: 'getcode/'
    })
}

// 爬取微博
export const getWeiBo = function () {
    return requests('news/weibo')
}

// 爬取知乎
export const getZhiHu = function () {
    return requests('news/zhihu')
}

// 爬取微信
export const getWeiXin = function () {
    return requests('news/weixin')
}

// 爬取百度
export const getBaiDu = function () {
    return requests('news/baidu')
}

// 全部文章
export const ArticleAll = function (pag) {
    return requests(`article/all?pag=${pag}`)
}

// 每日推荐
export const ArticleRecommend = function () {
    return requests('article/recommend')
}

// 文章详情
export const Article = function (nid, usernid) {
    return requests(`article/${nid}?usernid=${usernid}`)
}

// 文章评论
export const Comment = function (nid) {
    return requests(`comment/${nid}`)
}

// 我的文章列表
export const MyArticle = function (obj) {
    let url = `myarticle/${obj['nid']}`
    if (obj['pag']) {
        url += `?pag=${obj['pag']}`
    }
    return requests(url)
}

// 我的喜欢文章列表
export const MyLikeArticle = function (obj) {
    let url = `myarticle/like/${obj['nid']}`
    if (obj['pag']) {
        url += `?pag=${obj['pag']}`
    }
    return requests(url)
}

// 我的收藏文章列表
export const MyCollectsArticle = function (obj) {
    let url = `myarticle/collects/${obj['nid']}`
    if (obj['pag']) {
        url += `?pag=${obj['pag']}`
    }
    return requests(url)
}

// 文章筛选搜索
export const ArticleSearch = function (condition_obj) {
    let keys = Object.keys(condition_obj)
    let lit = ''
    for (let i = 0; i < keys.length; i++) {
        lit += keys[i] + '=' + condition_obj[[keys[i]]] + '&'
    }
    return requests('article/search/' + '?' + lit)
}

// 获取文章标签和分类，用于文章添加和编辑时的选择
export const getarticleinfo = function () {
    return requests('getarticle/tag/category')
}

// 添加文章
export const AddArticle = function (Article_obj) {
    return requests({
            url: 'addarticle',
            method: "post",
            data: Article_obj
        }
    )
}

// 删除文章
export const DelArticle = function (nid) {
    return requests.delete(`/delarticle/${nid}`)
}

// 添加和删除喜欢
export const Like = function (nid, usernid) {
    return requests(`like?nid=${nid}&user=${usernid}`)
}

// 添加和删除收藏
export const Collect = function (nid, usernid) {
    return requests(`collect?nid=${nid}&user=${usernid}`)
}

// 添加评论
export const addComment = function (data) {
    return requests.post(`addcomment`, data)
}

// 删除评论
export const delComment = function (data) {
    return requests.post(`delcomment`, data)
}

// 评论点赞
export const likeComment = function (nid) {
    return requests(`likecomment?nid=${nid}`)
}

// 获取全部头像，用于修改
export const avatars = function () {
    return requests('avatar/all')
}

// 修改头像
export const setAvatars = function (id) {
    return requests.post('avatar/edit', {nid: id})
}

// 获取用户信息
export const getuser = function (id) {
    return requests(`user/?nid=${id}`)
}

// 修改密码
export const editPassword = function (obj) {
    return requests.post('editpassword', obj)
}

//意见反馈
export const Feedback = function (obj) {
    return requests.post('feedback', obj)
}

// 文章搜索
export const Search = function (obj) {
    return requests.post('search', obj)
}

// 获取轮播图
export const Rotation = function (obj) {
    let url = `rotationimg?type=${obj['type']}`
    // 文章id
    if (obj['nid']) {
        url += `&nid=${obj['nid']}`
    }
    return requests(url)
}